home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
8_2.lha
/
8_2
/
8_2c.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
1KB
|
57 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ check a line to make sure it is made
/ up entirely of spaces and tabs
include <ctype.h>
tatic int isblankline(char *buf)
for ( ; *buf; buf++)
if (!isspace(*buf))
return 0;
return 1;
/ Input a series of lines into a name and address.
stream& operator>>(istream &in, name_and_address &x)
x.deallocate_name();
x.name = new char*[x.len = 6];
char **n = x.name;
for (int curlen = 0; ; curlen++, n++)
{
// read in a line
char buf[256], c;
in.get(buf, sizeof(buf));
in.get(c); // zap the newline
if (!in)
break;
// did we reach a blank line?
if (isblankline(buf))
break;
// reallocate if necessary
if (curlen >= x.len)
{
const int inc = 4;
char **svname = x.name;
x.name = new char*[x.len + inc];
memcpy((char*)x.name, (char*)svname,
x.len * sizeof(char*));
x.len += inc;
}
// save the line
*n = new char[strlen(buf) + 1];
strcpy(*n, buf);
}
*n = 0;
return in;